import 'package:flutter/material.dart';

/*
父组件管理状态
 */
class FatherManageDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new _FatherManageDemoState()
    ;
  }

}

class _FatherManageDemoState extends State<FatherManageDemo> {

  bool _active = false;

  void _handleTapChange(bool newValue) {
    setState(() {
      _active = newValue;
    });
  }

  @override
  Widget build(BuildContext context) {
    var mineManage = new GestureDetector(
      child: new BoxA(
        onChanged: _handleTapChange,
        active: _active,
      ),
    );

    return new Scaffold(
      appBar: new AppBar(title: new Text('自己管理状态'),),
      body: mineManage,
    );
  }
}

class BoxA extends StatelessWidget {

  BoxA({Key key, this.active: false, @required this.onChanged})
      :super(key: key);

  final bool active;

  final ValueChanged<bool> onChanged;

  void _handleTap() {
    onChanged(!active);
  }

  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
        onTap: _handleTap,
        child: new Container(
          child: new Center(
            child: new Text(active ? 'active' : 'inactive',
              style: new TextStyle(fontSize: 32.0, color: Colors.white),),
          ),
          width: 200.0,
          height: 200.0,
          decoration: new BoxDecoration(
            color: active ? Colors.lightGreen[600] : Colors.grey[600],
          ),
        )
    );
  }


}